// 导出所有钩子函数
import { useMapControl } from './useMapControl';
import { useMeasure } from './useMeasure';
import { useDraw } from './useDraw';

// 创建测量工具单例的工厂函数，确保它只被创建一次且状态正确
let measureToolsInstance = null;
const getMeasureTools = () => {
  if (!measureToolsInstance) {
    console.log('创建测量工具单例实例');
    measureToolsInstance = useMeasure();
    
    // 添加初始化完成后的回调
    const originalInitMap = measureToolsInstance.initMap;
    measureToolsInstance.initMap = (mapInstance) => {
      console.log('单例测量工具初始化地图');
      const result = originalInitMap(mapInstance);
      
      // 清除任何潜在的错误状态
      if (result && measureToolsInstance.hasError) {
        measureToolsInstance.hasError = false;
        measureToolsInstance.errorMsg = '';
        console.log('测量工具单例初始化成功，清除错误状态');
      }
      
      return result;
    };
  }
  return measureToolsInstance;
};

export {
  useMapControl,
  useMeasure,
  useDraw,
  getMeasureTools
}; 